/**
 * 
 */
package com.ld.tamp.web.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;

import com.ld.tamp.web.dao.AuthorizerInfoDao;
import com.ld.tamp.web.dao.AuthorizerJsTicketDao;
import com.ld.tamp.web.dao.ComponentAccessTokenDao;
import com.ld.tamp.web.event.AuthorizationEvent;
import com.ld.tamp.web.support.AuthorizerAccessTokenManager;
import com.ld.tamp.web.support.AuthorizerJsTicketManager;

import weixin.popular.bean.component.ApiQueryAuthResult.Authorization_info;

/**
 * 公众号授权事件监听
 * @author KeYang
 */
public class AuthorizationEventListener implements ApplicationListener<AuthorizationEvent>{

	private static final Logger logger = LoggerFactory.getLogger(AuthorizationEventListener.class);
	
	@Autowired
	private AuthorizerInfoDao authorizerInfoDao;
	
	@Autowired
	private AuthorizerJsTicketDao authorizerJsTicketDao;

	@Autowired
	private ComponentAccessTokenDao componentAccessTokenDao;
	
	
	@Override
	public void onApplicationEvent(AuthorizationEvent event) {
		Authorization_info authorizationInfo = event.getAuthorizationInfo();
		String authorizer_appid = authorizationInfo.getAuthorizer_appid();
		String authorizer_refresh_token = authorizationInfo.getAuthorizer_refresh_token();
		logger.info("公众号新授权，绑定定时刷新token和ticket任务，appid：{}",authorizationInfo.getAuthorizer_appid());
		AuthorizerAccessTokenManager.init(authorizer_appid, authorizer_refresh_token, 118, componentAccessTokenDao, authorizerInfoDao,authorizerJsTicketDao);
		
	}
}

